const state = {
    searchForm: {
        OrgIndex: {},
        UserIndex: {},
        AuthIndex: {},
        DepartmentIndex: {},
        DrgSettingsParams: {},
        DrgSettingsRule: {},
        DrgSettingsGroup: {},
        QCSettingsRate: {},
        QCSettingsRule: {},
        ConfigIndex: {},
        BasicDataPosition: {},
        BasicDataTitle: {},
        FeedbackIndex: {}
    }
}

const mutations = {
    SET_SEARCH_FORM_ITEM: (state, form) => {
        state.searchForm[form.pageName] = form.query
    },
    COVER_SEARCH_FORM_ITEM: (state, form) => {
        state.searchForm[form.pageName] = form.query
    },
    SET_SEARCH_FORM: (state, form) => {
        state.searchForm = form
    },
    CLEAR_ALL: (state, name) => {
        Object.keys(state.searchForm).forEach(key => {
            if (key !== name) {
                state.searchForm[key] = {}
            }
        })
    }
}

const actions = {
    setSearchFormItem ({ commit }, form) {
        commit('SET_SEARCH_FORM_ITEM', form)
    },
    coverSearchFormItem ({ commit }, form) {
        commit('COVER_SEARCH_FORM_ITEM', form)
    },
    setSearchForm ({ commit }, form) {
        commit('SET_SEARCH_FORM', form)
    },
    clearAll ({ commit }, name) {
        commit('CLEAR_ALL', name)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
